package com.group.three.service.impl;

import com.github.pagehelper.PageHelper;
import com.group.three.mapper.FavoriteVideosMapper;
import com.group.three.pojo.FavoriteVideos;
import com.group.three.service.FavoriteVideosService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FavoriteVideosServiceImpl implements FavoriteVideosService {
    @Autowired
    private FavoriteVideosMapper favoriteVideosMapper;


    @Override
    public List<FavoriteVideos> selectFavoriteAll() {
        PageHelper.startPage(1,5);
        return favoriteVideosMapper.selectFavoriteAll();
    }

    @Override
    public int deleteFavoriteVideosId(Long favoriteVideosId) {
        return favoriteVideosMapper.deleteFavoriteVideosId(favoriteVideosId);
    }

    @Override
    public List<FavoriteVideos> selectAll(int page, int size) {
        PageHelper.startPage(page,size);
        return favoriteVideosMapper.selectAll();
    }

    @Override
    public List<FavoriteVideos> searchByInput(String input) {
        return favoriteVideosMapper.searchByInput(input);
    }

    @Override
    public int insertVideo(Long FavoriteVideosId, Long videoNumber, Long personId, String collectionTime, Integer favoriteState) {
        return favoriteVideosMapper.insertVideo(FavoriteVideosId,videoNumber,personId,collectionTime,favoriteState);
    }


    /**
     * true 表示没喜欢，falsh表示已经喜欢了
     * @param videoNumber
     * @param personId
     * @return
     */
    @Override
    public boolean selectIsFavorite(Long videoNumber, Long personId,Integer favoriteState) {
        List<FavoriteVideos> favoriteVideos = favoriteVideosMapper.selectIsFavorite(videoNumber, personId,favoriteState);
        if (favoriteVideos.size()==0){
            //没有喜欢该视频
            return true;
        }else {
//            喜欢了
            return false;
        }
    }

    @Override
    public List<FavoriteVideos> selectAdminFavoriteVideosId(Long personId) {
        favoriteVideosMapper.selectAdminFavoriteVideosId(personId);
        return favoriteVideosMapper.selectAdminFavoriteVideosId(personId);
    }


    @Override
    public int deleteCancel(Long personId,Long videoNumber) {
        return favoriteVideosMapper.deleteCancel(personId,videoNumber);
    }
}
